﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 教师信息管理系统
{
    public partial class main : Form
    {
        SqlConnection conn;//创建连接对象的引用
        public main()
        {
            InitializeComponent();
        }

        private void main_Load(object sender, EventArgs e)
        {
            string sql = "server=.;database=teacher;integrated security=true;";
            conn = new SqlConnection(sql);
            conn.Open();
            if (conn.State == ConnectionState.Open)//判断链接状态
            {
                this.Text = "已连接!";
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if ((this.textBox1.Text == "") || (this.textBox2.Text == ""))
            {
                MessageBox.Show("用户名或密码不能为空!");
                return;
            }

            SqlCommand cmd = new SqlCommand();
            cmd.Connection = this.conn;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "select psd from userslogin where usersid='" + this.textBox1.Text + "'";
            string pwd = (string)cmd.ExecuteScalar();
            if (pwd == null)
            {
                MessageBox.Show("用户名不存在，请重试!");
            }
            else if (pwd != this.textBox2.Text)
            {
                MessageBox.Show("密码错误，请重试!");
            }
            else
            {
                if (radioButton1.Checked == true)
                {
                    MessageBox.Show("你好，管理员！");
                    teacherinfo teacinfo = new teacherinfo(this.textBox1.Text);
                    teacinfo.Show();
                    this.Hide();
                }
                else
                {
                    MessageBox.Show("登录成功!");
                    teacherinfo teacinfo = new teacherinfo(this.textBox1.Text);
                    teacinfo.Show();
                    this.Hide();
                }
            }

        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            regedit reg = new regedit();
            reg.Show();
            this.Hide();
        }
    }
}
